//
//  CreateNewMessageCell.m
//  SanYiTeaching
//
//  Created by 李文强 on 2019/4/30.
//  Copyright © 2019 SanYi. All rights reserved.
//

#import "CreateNewMessageCell.h"

@implementation CreateNewMessageCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self initSubView];
        [self layout];
    }
    return self;
}
- (void)initSubView{
    [self addSubview:self.leftTitleLabel];
    [self addSubview:self.selectedButton];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(buttonSelected:) name:@"SelectedTableCellOfCreateNewMessageNotice" object:nil];
}
- (void)buttonSelected:(NSNotification *)info{
    int indexPathRow = [[info.userInfo objectForKey:@"index"] intValue];
    if (indexPathRow == self.index) {
        self.selectedButton.selected = !self.selectedButton.selected;
    }
    
}

- (void)layout{
    [_leftTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@10);
        make.right.equalTo(self.mas_right).offset(-30);
        make.centerY.equalTo(self.mas_centerY);
        make.height.equalTo(@20);
    }];
    [_selectedButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@0).offset(-10);
        make.width.equalTo(@20);
        make.centerY.equalTo(self.mas_centerY);
        make.height.equalTo(@20);
    }];
}
- (UILabel *)leftTitleLabel{
    if (!_leftTitleLabel) {
        UILabel *label = [[UILabel alloc]init];
        label.text = @"班级1";
        label.textAlignment = 0;
        label.textColor = [UIColor darkGrayColor];
        label.font = [UIFont systemFontOfSize:14];
        _leftTitleLabel = label;
    }
    return _leftTitleLabel;
}
- (UIButton *)selectedButton{
    if (!_selectedButton) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setImage:[UIImage imageNamed:@"xiaoxi_duihao"] forState:UIControlStateSelected];
        button.titleLabel.font  = [UIFont systemFontOfSize:16];
        [button addTarget:self action:@selector(selectedButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        button.selected = NO;
        button.userInteractionEnabled = NO;
        _selectedButton =button;
    }
    return _selectedButton;
}
- (void)selectedButtonClick:(UIButton *)sender{
    sender.selected = !sender.selected;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
